#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：zhcx-service-test 
@File    ：listing_template_initialize_service.py
@Author  ：关依林
@Date    ：2023/8/14 17:24 
'''

from testcases.ProductGrading_Strategy.AmazonListing.controller.grading_base_way import *
from testcases.ProductGrading_Strategy.AmazonListing.service.listing_grading_public_way import *
from testcases.ProductGrading_Strategy.public_dispatch_way import getStrategyResult2


class TemplateInitializeVerify:

    def templateDataVerify(self):
        """

        验证思路: template + sourceId
        1.获取所有亚马逊有效来源渠道，以来源渠道维度分片
        2.根据模板ID获取模板规则
        3.根据分库将规则再次拆分组装
        4.利用索引分页过滤条件
        5.校验服务执行数据是否一致

        """
        statTime = time.time()
        cursorListing = connectMysql("Java_strategyListing_Test")
        cursorData = connectMysql("Java_strategyOrder_Test")
        orderSourceIdList = getCountryOrderSourceId(cursorData)
        templateCondition = getTemplateCondition(85)
        templateRule,templateRuleValue = orderTemplateRulePack(templateCondition)

        sourceData = []
        for orderSourceId in orderSourceIdList:
            id = getListingBaseId(orderSourceId)
            sourceData = list(set(gradingTemplateOrderType( templateRule, templateRuleValue, cursorListing, id, orderSourceId)))
        strategyResult = getStrategyResult2(85, orderSourceIdList[0])
        differentResult1 = tuple(set(sourceData) - set(strategyResult))
        differentResult2 = tuple(set(strategyResult) - set(sourceData))

        # if differentResult:
        #     report = f"--------------------------------------------------    \n" \
        #              f"Template-Listing订单类型,模板数据执行情况   \n" \
        #              f"在售数据: {count}    \n" \
        #              f"更新数据: {count - len(err_list)}    \n" \
        #              f"更新成功率: {'{:.2%}'.format((count - len(err_list)) / count)}  \n" \
        #              f"更新异常 {len(err_list)} 条,明细如下:    \n" \
        #              f"{err_list[0:20]}    \n"
        #     images = '![screenshot](https://img95.699pic.com/xsj/07/1s/fh.jpg%21/fh/300)   '
        #     DingTalkSendMsg().send_migration_report(report, images)
        # else:
        #     report = f"--------------------------------------------------    \n" \
        #              f"Template-Listing订单类型,模板数据执行情况   \n" \
        #              f"在售数据: {count}    \n" \
        #              f"更新数据: {count}    \n" \
        #              f"更新成功率: {'{:.2%}'.format((count - len(err_list)) / count)}  \n"
        #     images = '![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)'
        #     DingTalkSendMsg().send_migration_report(report, images)

        endTime = time.time()
        elapsedTime = round(endTime - statTime, 2)
        return sourceData

if __name__ == '__main__':
    TemplateInitializeVerify().templateDataVerify()